"use strict";
cc._RF.push(module, 'dfdec/ubdRPTqT73DOzLK8b', 'tipsPageSpNode');
// scripts/Game/Obj/tipsPageSpNode.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var TipsPage_1 = require("../Page/TipsPage");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var tipsPageSpNode = /** @class */ (function (_super) {
    __extends(tipsPageSpNode, _super);
    function tipsPageSpNode() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.maskNode = null;
        _this.sensitivityNum = 0.5;
        _this.oldScale = 0.3;
        _this.touchOne = null;
        _this.touchTwo = null;
        _this.tipsPage = null;
        _this.maxScale = 2;
        _this.moveMul = 1;
        _this.scaleMul = 1;
        _this.isTouchTwo = false;
        _this.isAni = false;
        _this.clickCount = 0;
        return _this;
    }
    tipsPageSpNode.prototype.onLoad = function () {
        this.node.on('touchstart', this.onTouchStart, this);
        this.node.on('touchmove', this.onTouchMove, this);
        this.node.on('touchend', this.onTouchEnd, this);
        this.node.on('touchcancel', this.onTouchCancel, this);
    };
    tipsPageSpNode.prototype.onTouchStart = function (e) {
        if (!this.touchTwo && this.touchOne)
            this.touchTwo = e.touch;
        if (!this.touchOne)
            this.touchOne = e.touch;
        this.isTouchTwo = false;
    };
    tipsPageSpNode.prototype.onTouchMove = function (e) {
        e.stopPropagation();
        // if (Normallevel134._instance.isPlaySound) return;
        var touches = e.getTouches();
        var touchPos = e.getLocation();
        var startTouchPos = e.getStartLocation();
        if (touchPos.sub(startTouchPos).mag() > 20) {
            this.isTouchTwo = true;
        }
        if (touches.length == 1) {
            var maxXDistance = ((this.node.width * this.node.scale) - this.node.width) / 2;
            var maxYDistance = ((this.node.height * this.node.scale) - this.node.height) / 2;
            var delta = e.getDelta().mulSelf(this.moveMul);
            var dx = delta.x;
            var dy = delta.y;
            if (this.node.x + dx < -maxXDistance) {
                dx = 0;
            }
            if (this.node.x + dx > maxXDistance) {
                dx = 0;
            }
            if (this.node.y + dy < -maxYDistance) {
                dy = 0;
            }
            if (this.node.y + dy > maxYDistance) {
                dy = 0;
            }
            this.node.x += dx;
            this.node.y += dy;
        }
        if (touches.length == 2) {
            var touch1 = touches[0], touch2 = touches[1];
            var delta1 = touch1.getDelta();
            var delta2 = touch2.getDelta();
            var touchPoint1 = this.node.convertToNodeSpaceAR(touch1.getLocation());
            var touchPoint2 = this.node.convertToNodeSpaceAR(touch2.getLocation());
            var distance = touchPoint1.sub(touchPoint2);
            var delta = delta1.sub(delta2).mulSelf(this.scaleMul);
            var scale = 1;
            if (Math.abs(distance.x) > Math.abs(distance.y)) {
                scale = (distance.x + delta.x) / distance.x * this.node.scaleX;
            }
            else {
                scale = (distance.y + delta.y) / distance.y * this.node.scaleY;
            }
            var pos = touchPoint2.add(cc.v2(distance.x / 2, distance.y / 2));
            //console.log("pos:",Math.floor(pos.x),Math.floor(pos.y));
            //滑轮缩放大小
            var scX = scale;
            //当前缩放值与原来缩放值之差
            var disScale = scX - this.node.scaleX;
            //当前点击的坐标与缩放值差像乘 
            var gapPos = pos.scale(cc.v2(disScale, disScale));
            //当前node坐标位置减去点击 点击坐标和缩放值的值
            var mapPos = this.node.getPosition().sub(gapPos);
            //console.log("mapPos:",Math.floor(mapPos.x),Math.floor(mapPos.y));
            //放大缩小
            if (this.isMinScale(scale))
                return;
            if (this.isMaxScale(scale))
                return;
            this.node.setScale(scale, scale);
            // let pre3 = cc.instantiate(this.redPre)
            // this.pre3 = pre3;
            // pre3.setPosition(pos)
            // pre3.scaleX = 2
            // pre3.scaleY = 2
            // this.node.addChild(pre3);
            //移动地图坐标
            this.node.setPosition(mapPos);
            this.fixPos(cc.v2(0, 0));
        }
    };
    tipsPageSpNode.prototype.onTouchEnd = function (e) {
        var _this = this;
        // let touchs = e.getTouches();
        if (this.isTouchTwo)
            return;
        // console.log(touchs.length,"?????????????????")
        // console.log("松开节点????????????");
        // if (this.node.scale <= 1) {
        //     this.node.scale = 1;
        //     this.node.setPosition(cc.Vec3.ZERO);
        // }
        if (this.isAni)
            return;
        this.clickCount++;
        if (this.clickCount == 1) {
            this.scheduleOnce(this.hideSp, 0.2);
            // this.clickCount = 0;
        }
        else {
            this.unschedule(this.hideSp);
            this.isAni = true;
            this.clickCount = 0;
            if (this.node.scale > 1) {
                cc.tween(this.node).to(0.2, { scale: 1, x: 0, y: 0 }).call(function () {
                    _this.isAni = false;
                }).start();
            }
            else {
                cc.tween(this.node).to(0.2, { scale: 1.5 }).call(function () {
                    _this.isAni = false;
                }).start();
            }
        }
    };
    tipsPageSpNode.prototype.onDisable = function () {
        this.node.scale = 1;
        this.isAni = false;
        this.isTouchTwo = false;
    };
    tipsPageSpNode.prototype.hideSp = function () {
        var _a, _b;
        this.clickCount = 0;
        (_a = this.tipsPage) === null || _a === void 0 ? void 0 : _a.closeSpScale();
        (_b = this.tipsPage) === null || _b === void 0 ? void 0 : _b.closeAnswerScale();
    };
    tipsPageSpNode.prototype.onTouchCancel = function (e) {
        // console.log("离开节点?????????");
        // if (this.node.scale <= 1) {
        //     this.node.scale = 1;
        //     this.node.setPosition(cc.Vec3.ZERO);
        // }
    };
    //修正坐标
    tipsPageSpNode.prototype.fixPos = function (delta) {
        var x = this.node.x + delta.x;
        var y = this.node.y + delta.y;
        var cW = this.node.width * this.node.scaleX;
        var cH = this.node.height * this.node.scaleY;
        var winSize = cc.size(this.node.getContentSize()); //cc.winSize
        var xMin = -cW / 2 + winSize.width / 2;
        var xMax = cW / 2 - winSize.width / 2;
        var yMin = -cH / 2 + winSize.height / 2;
        var yMax = cH / 2 - winSize.height / 2;
        x = x > xMax ? xMax : x;
        x = x < xMin ? xMin : x;
        y = y > yMax ? yMax : y;
        y = y < yMin ? yMin : y;
        //console.log("移动",x,y);
        // cc.vv.mapPos = cc.v2(x, y);
        // cc.vv.mapScale = this.node.scaleX;
        this.node.setPosition(cc.v2(x, y));
    };
    //是否最大缩放
    tipsPageSpNode.prototype.isMaxScale = function (sc) {
        return sc > this.maxScale;
    };
    //是否最小缩放
    tipsPageSpNode.prototype.isMinScale = function (sc) {
        // return false;
        return this.getMinScale() > sc;
    };
    //获取最小缩放比
    tipsPageSpNode.prototype.getMinScale = function () {
        return 1;
        //console.log(cc.view.getCanvasSize().width,cc.view.getCanvasSize().height)
        //console.log(cc.winSize.width,cc.winSize.height)
        var windowSize = cc.size(this.node.parent.getContentSize()); //cc.winSize;
        var mapRect = this.node;
        var scaleX = windowSize.width / mapRect.width;
        var scaleY = windowSize.height / mapRect.height;
        var scale = scaleX > scaleY ? scaleX : scaleY;
        //console.log("scale",scale)
        return scale;
    };
    __decorate([
        property({ type: cc.Node, displayName: "mask节点" })
    ], tipsPageSpNode.prototype, "maskNode", void 0);
    __decorate([
        property({ type: TipsPage_1.default, displayName: "提示界面" })
    ], tipsPageSpNode.prototype, "tipsPage", void 0);
    __decorate([
        property({ displayName: "最大缩放倍数" })
    ], tipsPageSpNode.prototype, "maxScale", void 0);
    __decorate([
        property({ type: cc.Float })
    ], tipsPageSpNode.prototype, "moveMul", void 0);
    __decorate([
        property({ type: cc.Float })
    ], tipsPageSpNode.prototype, "scaleMul", void 0);
    tipsPageSpNode = __decorate([
        ccclass
    ], tipsPageSpNode);
    return tipsPageSpNode;
}(cc.Component));
exports.default = tipsPageSpNode;

cc._RF.pop();